package com.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;

/**
 * 组合
 *
 */
public class StreamDemo3 {
    public static void main(String[] args) {
        Integer[] ints = {1, 2, 3, 4};
        ArrayList<Integer> list = new ArrayList<>(Arrays.asList(ints));

        Optional<Integer> reduce = list.stream().reduce((a, b) -> a + b);//没有初始值
        System.out.println(reduce.orElse(0));

        System.out.println(list.stream().reduce(6, (a, b) -> a + b));  //初始值是6


    }
}
